#ifndef _SOMB_LOG_H_
#define _SOMB_LOG_H_

#include <time.h>
#include <sys/time.h>
#include <stdio.h>

typedef enum
{
    SOMB_LOG_LEVEL_DEBUG,
    SOMB_LOG_LEVEL_INFO,
    SOMB_LOG_LEVEL_WARN,
    SOMB_LOG_LEVEL_ERROR,
}SOMB_LOG_LEVEL;


#if 0

#define filename(x) strrchr(x,'/')?strrchr(x,'/')+1:x
#define SOMB_LOG_ERR(fmt,args...) \
    do{ \
        struct timeval __tmp_tv;\
        gettimeofday(&__tmp_tv,NULL);\
        printf("%ld.%06ld###%s:%s:%d "fmt"\n",__tmp_tv.tv_sec,__tmp_tv.tv_usec,filename(__FILE__), __FUNCTION__,__LINE__, ##args); \
    }while(0);
#define SOMB_LOG_WARN(fmt,args...)  \
    do{ \
        struct timeval __tmp_tv;\
        gettimeofday(&__tmp_tv,NULL);\
        printf("%ld.%06ld###%s:%s:%d "fmt"\n",__tmp_tv.tv_sec,__tmp_tv.tv_usec,filename(__FILE__), __FUNCTION__,__LINE__, ##args); \
    }while(0);

#define SOMB_LOG_INFO(fmt,args...)  \
    do{ \
        struct timeval __tmp_tv;\
        gettimeofday(&__tmp_tv,NULL);\
        printf("%ld.%06ld  %s:%s:%d "fmt"\n",__tmp_tv.tv_sec,__tmp_tv.tv_usec,filename(__FILE__), __FUNCTION__,__LINE__, ##args); \
    }while(0);

#define SOMB_LOG_DEBUG(fmt,args...) \
    do{ \
        struct timeval __tmp_tv;\
        gettimeofday(&__tmp_tv,NULL);\
        printf("%ld.%06ld  %s:%s:%d "fmt"\n",__tmp_tv.tv_sec,__tmp_tv.tv_usec,filename(__FILE__), __FUNCTION__,__LINE__, ##args); \
    }while(0);



#endif

typedef struct 
{
    char log_path[256];
    uint32_t log_level;
    uint32_t log_file_size;
    uint32_t log_file_num;
}st_somb_logfile_config;

extern int32_t somb_log_init(st_somb_logfile_config *stlogfileconf);

extern void somb_log_record(int32_t level,char *fmt,...);
#define SOMB_LOG(level,fmt,args...) \
    do{ \
        somb_log_record(level," %s:%d "fmt"\n",__FUNCTION__,__LINE__,##args);\
    }while(0);

#define SOMB_LOG_ERR(fmt,...)       SOMB_LOG(SOMB_LOG_LEVEL_ERROR,fmt,##__VA_ARGS__)
#define SOMB_LOG_WARN(fmt,...)      SOMB_LOG(SOMB_LOG_LEVEL_WARN,fmt,##__VA_ARGS__)
#define SOMB_LOG_INFO(fmt,...)      SOMB_LOG(SOMB_LOG_LEVEL_INFO,fmt,##__VA_ARGS__)
#define SOMB_LOG_DEBUG(fmt,...)     SOMB_LOG(SOMB_LOG_LEVEL_DEBUG,fmt,##__VA_ARGS__)
#endif //_SOMB_LOG_H_
